// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyQueryOverTimeAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>
#include <PyQueryAttributes.h>
#include <PyPickAttributes.h>

// ****************************************************************************
// Module: PyQueryOverTimeAttributes
//
// Purpose:
//   Attributes for queries over time.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a QueryOverTimeAttributes.
//
struct QueryOverTimeAttributesObject
{
    PyObject_HEAD
    QueryOverTimeAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewQueryOverTimeAttributes(int);
std::string
PyQueryOverTimeAttributes_ToString(const QueryOverTimeAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    const char *timeType_names = "Cycle, DTime, Timestep";
    switch (atts->GetTimeType())
    {
      case QueryOverTimeAttributes::Cycle:
          snprintf(tmpStr, 1000, "%stimeType = %sCycle  # %s\n", prefix, prefix, timeType_names);
          str += tmpStr;
          break;
      case QueryOverTimeAttributes::DTime:
          snprintf(tmpStr, 1000, "%stimeType = %sDTime  # %s\n", prefix, prefix, timeType_names);
          str += tmpStr;
          break;
      case QueryOverTimeAttributes::Timestep:
          snprintf(tmpStr, 1000, "%stimeType = %sTimestep  # %s\n", prefix, prefix, timeType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    if(atts->GetStartTimeFlag())
        snprintf(tmpStr, 1000, "%sstartTimeFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sstartTimeFlag = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sstartTime = %d\n", prefix, atts->GetStartTime());
    str += tmpStr;
    if(atts->GetEndTimeFlag())
        snprintf(tmpStr, 1000, "%sendTimeFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sendTimeFlag = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sendTime = %d\n", prefix, atts->GetEndTime());
    str += tmpStr;
    if(atts->GetStrideFlag())
        snprintf(tmpStr, 1000, "%sstrideFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sstrideFlag = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sstride = %d\n", prefix, atts->GetStride());
    str += tmpStr;
    if(atts->GetCreateWindow())
        snprintf(tmpStr, 1000, "%screateWindow = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%screateWindow = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%swindowId = %d\n", prefix, atts->GetWindowId());
    str += tmpStr;
    {   const doubleVector &cachedCurvePts = atts->GetCachedCurvePts();
        snprintf(tmpStr, 1000, "%scachedCurvePts = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < cachedCurvePts.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", cachedCurvePts[i]);
            str += tmpStr;
            if(i < cachedCurvePts.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    if(atts->GetUseCachedPts())
        snprintf(tmpStr, 1000, "%suseCachedPts = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%suseCachedPts = 0\n", prefix);
    str += tmpStr;
    return str;
}

static PyObject *
QueryOverTimeAttributes_Notify(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_SetTimeType(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid timeType value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Cycle";
        ss << ", DTime";
        ss << ", Timestep";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the timeType in the object.
    obj->data->SetTimeType(QueryOverTimeAttributes::TimeType(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_GetTimeType(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetTimeType()));
    return retval;
}

/*static*/ PyObject *
QueryOverTimeAttributes_SetStartTimeFlag(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the startTimeFlag in the object.
    obj->data->SetStartTimeFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_GetStartTimeFlag(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetStartTimeFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
QueryOverTimeAttributes_SetStartTime(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the startTime in the object.
    obj->data->SetStartTime(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_GetStartTime(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetStartTime()));
    return retval;
}

/*static*/ PyObject *
QueryOverTimeAttributes_SetEndTimeFlag(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the endTimeFlag in the object.
    obj->data->SetEndTimeFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_GetEndTimeFlag(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetEndTimeFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
QueryOverTimeAttributes_SetEndTime(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the endTime in the object.
    obj->data->SetEndTime(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_GetEndTime(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetEndTime()));
    return retval;
}

/*static*/ PyObject *
QueryOverTimeAttributes_SetStrideFlag(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the strideFlag in the object.
    obj->data->SetStrideFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_GetStrideFlag(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetStrideFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
QueryOverTimeAttributes_SetStride(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the stride in the object.
    obj->data->SetStride(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_GetStride(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetStride()));
    return retval;
}

/*static*/ PyObject *
QueryOverTimeAttributes_SetCreateWindow(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the createWindow in the object.
    obj->data->SetCreateWindow(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_GetCreateWindow(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetCreateWindow()?1L:0L);
    return retval;
}

/*static*/ PyObject *
QueryOverTimeAttributes_SetWindowId(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the windowId in the object.
    obj->data->SetWindowId(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_GetWindowId(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetWindowId()));
    return retval;
}

/*static*/ PyObject *
QueryOverTimeAttributes_SetCachedCurvePts(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetCachedCurvePts() = vec;
    // Mark the cachedCurvePts in the object as modified.
    obj->data->SelectCachedCurvePts();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_GetCachedCurvePts(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the cachedCurvePts.
    const doubleVector &cachedCurvePts = obj->data->GetCachedCurvePts();
    PyObject *retval = PyTuple_New(cachedCurvePts.size());
    for(size_t i = 0; i < cachedCurvePts.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(cachedCurvePts[i]));
    return retval;
}

/*static*/ PyObject *
QueryOverTimeAttributes_SetUseCachedPts(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the useCachedPts in the object.
    obj->data->SetUseCachedPts(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
QueryOverTimeAttributes_GetUseCachedPts(PyObject *self, PyObject *args)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetUseCachedPts()?1L:0L);
    return retval;
}



PyMethodDef PyQueryOverTimeAttributes_methods[QUERYOVERTIMEATTRIBUTES_NMETH] = {
    {"Notify", QueryOverTimeAttributes_Notify, METH_VARARGS},
    {"SetTimeType", QueryOverTimeAttributes_SetTimeType, METH_VARARGS},
    {"GetTimeType", QueryOverTimeAttributes_GetTimeType, METH_VARARGS},
    {"SetStartTimeFlag", QueryOverTimeAttributes_SetStartTimeFlag, METH_VARARGS},
    {"GetStartTimeFlag", QueryOverTimeAttributes_GetStartTimeFlag, METH_VARARGS},
    {"SetStartTime", QueryOverTimeAttributes_SetStartTime, METH_VARARGS},
    {"GetStartTime", QueryOverTimeAttributes_GetStartTime, METH_VARARGS},
    {"SetEndTimeFlag", QueryOverTimeAttributes_SetEndTimeFlag, METH_VARARGS},
    {"GetEndTimeFlag", QueryOverTimeAttributes_GetEndTimeFlag, METH_VARARGS},
    {"SetEndTime", QueryOverTimeAttributes_SetEndTime, METH_VARARGS},
    {"GetEndTime", QueryOverTimeAttributes_GetEndTime, METH_VARARGS},
    {"SetStrideFlag", QueryOverTimeAttributes_SetStrideFlag, METH_VARARGS},
    {"GetStrideFlag", QueryOverTimeAttributes_GetStrideFlag, METH_VARARGS},
    {"SetStride", QueryOverTimeAttributes_SetStride, METH_VARARGS},
    {"GetStride", QueryOverTimeAttributes_GetStride, METH_VARARGS},
    {"SetCreateWindow", QueryOverTimeAttributes_SetCreateWindow, METH_VARARGS},
    {"GetCreateWindow", QueryOverTimeAttributes_GetCreateWindow, METH_VARARGS},
    {"SetWindowId", QueryOverTimeAttributes_SetWindowId, METH_VARARGS},
    {"GetWindowId", QueryOverTimeAttributes_GetWindowId, METH_VARARGS},
    {"SetCachedCurvePts", QueryOverTimeAttributes_SetCachedCurvePts, METH_VARARGS},
    {"GetCachedCurvePts", QueryOverTimeAttributes_GetCachedCurvePts, METH_VARARGS},
    {"SetUseCachedPts", QueryOverTimeAttributes_SetUseCachedPts, METH_VARARGS},
    {"GetUseCachedPts", QueryOverTimeAttributes_GetUseCachedPts, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
QueryOverTimeAttributes_dealloc(PyObject *v)
{
   QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *QueryOverTimeAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyQueryOverTimeAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "timeType") == 0)
        return QueryOverTimeAttributes_GetTimeType(self, NULL);
    if(strcmp(name, "Cycle") == 0)
        return PyInt_FromLong(long(QueryOverTimeAttributes::Cycle));
    if(strcmp(name, "DTime") == 0)
        return PyInt_FromLong(long(QueryOverTimeAttributes::DTime));
    if(strcmp(name, "Timestep") == 0)
        return PyInt_FromLong(long(QueryOverTimeAttributes::Timestep));

    if(strcmp(name, "startTimeFlag") == 0)
        return QueryOverTimeAttributes_GetStartTimeFlag(self, NULL);
    if(strcmp(name, "startTime") == 0)
        return QueryOverTimeAttributes_GetStartTime(self, NULL);
    if(strcmp(name, "endTimeFlag") == 0)
        return QueryOverTimeAttributes_GetEndTimeFlag(self, NULL);
    if(strcmp(name, "endTime") == 0)
        return QueryOverTimeAttributes_GetEndTime(self, NULL);
    if(strcmp(name, "strideFlag") == 0)
        return QueryOverTimeAttributes_GetStrideFlag(self, NULL);
    if(strcmp(name, "stride") == 0)
        return QueryOverTimeAttributes_GetStride(self, NULL);
    if(strcmp(name, "createWindow") == 0)
        return QueryOverTimeAttributes_GetCreateWindow(self, NULL);
    if(strcmp(name, "windowId") == 0)
        return QueryOverTimeAttributes_GetWindowId(self, NULL);
    if(strcmp(name, "cachedCurvePts") == 0)
        return QueryOverTimeAttributes_GetCachedCurvePts(self, NULL);
    if(strcmp(name, "useCachedPts") == 0)
        return QueryOverTimeAttributes_GetUseCachedPts(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyQueryOverTimeAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyQueryOverTimeAttributes_methods[i].ml_name),
                PyString_FromString(PyQueryOverTimeAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyQueryOverTimeAttributes_methods, self, name);
}

int
PyQueryOverTimeAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "timeType") == 0)
        obj = QueryOverTimeAttributes_SetTimeType(self, args);
    else if(strcmp(name, "startTimeFlag") == 0)
        obj = QueryOverTimeAttributes_SetStartTimeFlag(self, args);
    else if(strcmp(name, "startTime") == 0)
        obj = QueryOverTimeAttributes_SetStartTime(self, args);
    else if(strcmp(name, "endTimeFlag") == 0)
        obj = QueryOverTimeAttributes_SetEndTimeFlag(self, args);
    else if(strcmp(name, "endTime") == 0)
        obj = QueryOverTimeAttributes_SetEndTime(self, args);
    else if(strcmp(name, "strideFlag") == 0)
        obj = QueryOverTimeAttributes_SetStrideFlag(self, args);
    else if(strcmp(name, "stride") == 0)
        obj = QueryOverTimeAttributes_SetStride(self, args);
    else if(strcmp(name, "createWindow") == 0)
        obj = QueryOverTimeAttributes_SetCreateWindow(self, args);
    else if(strcmp(name, "windowId") == 0)
        obj = QueryOverTimeAttributes_SetWindowId(self, args);
    else if(strcmp(name, "cachedCurvePts") == 0)
        obj = QueryOverTimeAttributes_SetCachedCurvePts(self, args);
    else if(strcmp(name, "useCachedPts") == 0)
        obj = QueryOverTimeAttributes_SetUseCachedPts(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
QueryOverTimeAttributes_print(PyObject *v, FILE *fp, int flags)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)v;
    fprintf(fp, "%s", PyQueryOverTimeAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
QueryOverTimeAttributes_str(PyObject *v)
{
    QueryOverTimeAttributesObject *obj = (QueryOverTimeAttributesObject *)v;
    return PyString_FromString(PyQueryOverTimeAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *QueryOverTimeAttributes_Purpose = "Attributes for queries over time.";
#else
static char *QueryOverTimeAttributes_Purpose = "Attributes for queries over time.";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(QueryOverTimeAttributesType,         \
                  "QueryOverTimeAttributes",           \
                  QueryOverTimeAttributesObject,       \
                  QueryOverTimeAttributes_dealloc,     \
                  QueryOverTimeAttributes_print,       \
                  PyQueryOverTimeAttributes_getattr,   \
                  PyQueryOverTimeAttributes_setattr,   \
                  QueryOverTimeAttributes_str,         \
                  QueryOverTimeAttributes_Purpose,     \
                  QueryOverTimeAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
QueryOverTimeAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &QueryOverTimeAttributesType
         || Py_TYPE(other) != &QueryOverTimeAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    QueryOverTimeAttributes *a = ((QueryOverTimeAttributesObject *)self)->data;
    QueryOverTimeAttributes *b = ((QueryOverTimeAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static QueryOverTimeAttributes *defaultAtts = 0;
static QueryOverTimeAttributes *currentAtts = 0;

static PyObject *
NewQueryOverTimeAttributes(int useCurrent)
{
    QueryOverTimeAttributesObject *newObject;
    newObject = PyObject_NEW(QueryOverTimeAttributesObject, &QueryOverTimeAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new QueryOverTimeAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new QueryOverTimeAttributes(*defaultAtts);
    else
        newObject->data = new QueryOverTimeAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapQueryOverTimeAttributes(const QueryOverTimeAttributes *attr)
{
    QueryOverTimeAttributesObject *newObject;
    newObject = PyObject_NEW(QueryOverTimeAttributesObject, &QueryOverTimeAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (QueryOverTimeAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
QueryOverTimeAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewQueryOverTimeAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef QueryOverTimeAttributesMethods[] = {
    {"QueryOverTimeAttributes", QueryOverTimeAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *QueryOverTimeAttributesObserver = 0;

std::string
PyQueryOverTimeAttributes_GetLogString()
{
    std::string s("QueryOverTimeAtts = GetQueryOverTimeAttributes()\n");
    if(currentAtts != 0)
        s += PyQueryOverTimeAttributes_ToString(currentAtts, "QueryOverTimeAtts.");
    return s;
}

static void
PyQueryOverTimeAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("QueryOverTimeAtts = GetQueryOverTimeAttributes()\n");
        s += PyQueryOverTimeAttributes_ToString(currentAtts, "QueryOverTimeAtts.");
        cb(s);
    }
}

void
PyQueryOverTimeAttributes_StartUp(QueryOverTimeAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyQueryOverTimeAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(QueryOverTimeAttributesObserver == 0)
    {
        QueryOverTimeAttributesObserver = new ObserverToCallback(subj,
            PyQueryOverTimeAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyQueryOverTimeAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete QueryOverTimeAttributesObserver;
    QueryOverTimeAttributesObserver = 0;
}

PyMethodDef *
PyQueryOverTimeAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return QueryOverTimeAttributesMethods;
}

bool
PyQueryOverTimeAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &QueryOverTimeAttributesType);
}

QueryOverTimeAttributes *
PyQueryOverTimeAttributes_FromPyObject(PyObject *obj)
{
    QueryOverTimeAttributesObject *obj2 = (QueryOverTimeAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyQueryOverTimeAttributes_New()
{
    return NewQueryOverTimeAttributes(0);
}

PyObject *
PyQueryOverTimeAttributes_Wrap(const QueryOverTimeAttributes *attr)
{
    return WrapQueryOverTimeAttributes(attr);
}

void
PyQueryOverTimeAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    QueryOverTimeAttributesObject *obj2 = (QueryOverTimeAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyQueryOverTimeAttributes_SetDefaults(const QueryOverTimeAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new QueryOverTimeAttributes(*atts);
}

